// 导航栏
window.onscroll = function () {
    scroll()
}
function scroll() {
    let topbg = document.querySelector(".top-bg");
    if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
        topbg.style.display = "block";
    }
    else {
        topbg.style.display = "none";
    }
}

// 为B端.....
function showDIv(divId, TextId) {
    //隐藏所有div
    document.getElementById("div1").classList.add("slotion-hidden");
    document.getElementById("div2").classList.add("slotion-hidden");
    document.getElementById("div3").classList.add("slotion-hidden");
    document.getElementById("div4").classList.add("slotion-hidden");
    document.getElementById("div5").classList.add("slotion-hidden");
    document.getElementById("div6").classList.add("slotion-hidden");
    document.getElementById("div7").classList.add("slotion-hidden");
    document.getElementById("div8").classList.add("slotion-hidden");
    document.getElementById("div9").classList.add("slotion-hidden");
    //移除所有文本的激活样式
    document.getElementById("text1").classList.remove("sloution-li");
    document.getElementById("text2").classList.remove("sloution-li");
    document.getElementById("text3").classList.remove("sloution-li");
    document.getElementById("text4").classList.remove("sloution-li");
    document.getElementById("text5").classList.remove("sloution-li");
    document.getElementById("text6").classList.remove("sloution-li");
    document.getElementById("text7").classList.remove("sloution-li");
    document.getElementById("text8").classList.remove("sloution-li");
    document.getElementById("text9").classList.remove("sloution-li");
    // 显示选中的 div 并添加激活样式到对应的文本
    document.getElementById(divId).classList.remove('slotion-hidden');
    document.getElementById(TextId).classList.add('sloution-li');
}
// 初始化显示 div1 和 文本一
window.onload = function () {
    showDIv('div1', 'text1');
};
// 轮播
let num = 0;
let lunbo; // 定义为全局变量，便于控制

const lundiv = [
    document.getElementById("div1"),
    document.getElementById("div2"),
    document.getElementById("div3"),
    document.getElementById("div4"),
    document.getElementById("div5"),
    document.getElementById("div6"),
    document.getElementById("div7"),
    document.getElementById("div8"),
    document.getElementById("div9")
];

const luntext = [
    document.getElementById("text1"),
    document.getElementById("text2"),
    document.getElementById("text3"),
    document.getElementById("text4"),
    document.getElementById("text5"),
    document.getElementById("text6"),
    document.getElementById("text7"),
    document.getElementById("text8"),
    document.getElementById("text9")
];

// 显示指定的 div 和激活对应文本
function showDIv(divId, textId) {
    // 隐藏所有 div
    lundiv.forEach(div => div.classList.add("slotion-hidden"));
    // 移除所有文本的激活类
    luntext.forEach(text => text.classList.remove("sloution-li"));

    // 显示当前项
    document.getElementById(divId).classList.remove("slotion-hidden");
    document.getElementById(textId).classList.add("sloution-li");

    // 更新 num 为当前索引
    const index = parseInt(divId.replace("div", "")) - 1;
    num = index;
}

// 启动轮播
function startCarousel() {
    lunbo = setInterval(() => {
        const nextIndex = (num + 1) % 9;
        const nextDiv = "div" + (nextIndex + 1);
        const nextText = "text" + (nextIndex + 1);
        showDIv(nextDiv, nextText);
    }, 2000);
}

// 初始化
window.onload = function () {
    showDIv('div1', 'text1');
    startCarousel(); // 开始轮播
};

// 绑定点击事件：点击文字时切换并暂停轮播
luntext.forEach((textEl, index) => {
    textEl.addEventListener("click", () => {
        clearInterval(lunbo); // 暂停轮播

        const divId = "div" + (index + 1);
        const textId = "text" + (index + 1);
        showDIv(divId, textId);

        // 5秒后重启轮播
        setTimeout(() => {
            clearInterval(lunbo); // 清除可能存在的旧定时器
            startCarousel();
        }, 3000);
    });
});